aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/[username]
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-11-08 16:33:17 -0800
committerAdam Soltys <[email protected]>2022-11-08 16:33:49 -0800
commit376ff340ad9a0e15efec997c560f7e4db765f65c (patch)
treee2f28b2367c0ae9567447b5bec49f2f59126f8b0 /src/routes/(app)/[username]
parent4b15454e4b37e212a646d5b85fea7ae8eab374e2 (diff)
downloadcoinos-ui-376ff340ad9a0e15efec997c560f7e4db765f65c.tar.gz
coinos-ui-376ff340ad9a0e15efec997c560f7e4db765f65c.zip
handle on-chain deposits
Diffstat (limited to 'src/routes/(app)/[username]')
-rw-r--r--src/routes/(app)/[username]/address/+page.server.js13
-rw-r--r--src/routes/(app)/[username]/address/+page.svelte (renamed from src/routes/(app)/[username]/bitcoin/+page.svelte)0
-rw-r--r--src/routes/(app)/[username]/bitcoin/+page.server.js4
-rw-r--r--src/routes/(app)/[username]/dashboard/+page.svelte28
-rw-r--r--src/routes/(app)/[username]/receive/[...recipient]/+page.svelte2
-rw-r--r--src/routes/(app)/[username]/transactions/[...page]/+page.svelte96
6 files changed, 78 insertions, 65 deletions
diff --git a/src/routes/(app)/[username]/address/+page.server.js b/src/routes/(app)/[username]/address/+page.server.js
new file mode 100644
index 00000000..c18bcdba
--- /dev/null
+++ b/src/routes/(app)/[username]/address/+page.server.js
@@ -0,0 +1,13 @@
+import { auth, get, post } from '$lib/utils';
+import { redirect } from '@sveltejs/kit';
+
+export async function load({ cookies, params, parent }) {
+ let user = (await parent()).subject;
+ let rates = await get('/rates');
+ let invoice = {
+ network: 'bitcoin',
+ rate: rates[user.currency]
+ };
+ let { uuid } = await post('/invoice', { invoice, user }, auth(cookies));
+ throw redirect(307, `/invoice/${uuid}`);
+}
diff --git a/src/routes/(app)/[username]/bitcoin/+page.svelte b/src/routes/(app)/[username]/address/+page.svelte
index e69de29b..e69de29b 100644
--- a/src/routes/(app)/[username]/bitcoin/+page.svelte
+++ b/src/routes/(app)/[username]/address/+page.svelte
diff --git a/src/routes/(app)/[username]/bitcoin/+page.server.js b/src/routes/(app)/[username]/bitcoin/+page.server.js
deleted file mode 100644
index 7ef65346..00000000
--- a/src/routes/(app)/[username]/bitcoin/+page.server.js
+++ /dev/null
@@ -1,4 +0,0 @@
-import { redirect } from '@sveltejs/kit';
-export async function load({ params }) {
- throw redirect(303, `/${params.username}`);
-}
diff --git a/src/routes/(app)/[username]/dashboard/+page.svelte b/src/routes/(app)/[username]/dashboard/+page.svelte
index 93fac986..0ea0e0a8 100644
--- a/src/routes/(app)/[username]/dashboard/+page.svelte
+++ b/src/routes/(app)/[username]/dashboard/+page.svelte
@@ -52,23 +52,25 @@
</div>
<div class="grid sm:grid-cols-2 gap-2 mt-8">
+ <a href="/send">
+ <button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
+ >{$t('user.dashboard.withdraw')}</button
+ >
+ </a>
<a href={`/${user.username}/receive`}>
<button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
>{$t('user.dashboard.receive')}</button
>
</a>
- {#if user.account.balance > 0}
- <a href="/send">
- <button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
- >{$t('user.dashboard.withdraw')}</button
- >
- </a>
- {:else}
- <a href={`/${user.username}/settings`}>
- <button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
- >Setup Account</button
- >
- </a>
- {/if}
+ <a href={`/${user.username}/settings`}>
+ <button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
+ >Setup Account</button
+ >
+ </a>
+ <a href={`/${user.username}/address`}>
+ <button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
+ >Deposit</button
+ >
+ </a>
</div>
</div>
diff --git a/src/routes/(app)/[username]/receive/[...recipient]/+page.svelte b/src/routes/(app)/[username]/receive/[...recipient]/+page.svelte
index 634b091a..41958cd0 100644
--- a/src/routes/(app)/[username]/receive/[...recipient]/+page.svelte
+++ b/src/routes/(app)/[username]/receive/[...recipient]/+page.svelte
@@ -56,7 +56,7 @@
<input type="hidden" name="amount" value={amount} />
<input type="hidden" name="currency" value={currency} />
<input type="hidden" name="username" value={username} />
- <input type="hidden" name="network" value={network} />
+ <input type="hidden" name="network" value={network} />
{#if req}
<input type="hidden" name="requester" value={req.requester.username} />
diff --git a/src/routes/(app)/[username]/transactions/[...page]/+page.svelte b/src/routes/(app)/[username]/transactions/[...page]/+page.svelte
index f5fae1d9..c7007af4 100644
--- a/src/routes/(app)/[username]/transactions/[...page]/+page.svelte
+++ b/src/routes/(app)/[username]/transactions/[...page]/+page.svelte
@@ -2,7 +2,7 @@
import { Avatar, Icon } from '$comp';
import { onMount } from 'svelte';
import { format, parseISO } from 'date-fns';
- import { newPayment } from '$lib/store';
+ import { newPayment, txns } from '$lib/store';
import { t } from '$lib/translations';
import { f, s, sat, sats } from '$lib/utils';
import { page } from '$app/stores';
@@ -31,17 +31,21 @@
pages = [];
$: data && ({ page: p, pages, start, end, total, transactions } = data);
+ $: console.log($txns.length), ($txns = transactions);
+
$: $page && ($newPayment = false);
$: $newPayment && invalidate(`/users/${user.username}`);
- $: path = $page.url.pathname.substring(0, $page.url.pathname.lastIndexOf('/'));
+ $: path = $page.params.page
+ ? $page.url.pathname.substring(0, $page.url.pathname.lastIndexOf('/'))
+ : $page.url.pathname;
let csv = () => {
const keys = ['hash', 'updatedAt', 'rate', 'currency', 'amount', 'fee', 'tip'];
const csv =
keys.map((k) => `"${k}"`).join(',') +
'\n' +
- transactions.map((r) => keys.map((k) => `"${r[k]}"`).join(',')).join('\n');
+ $txns.map((r) => keys.map((k) => `"${r[k]}"`).join(',')).join('\n');
const filename = 'transactions.csv';
let blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
@@ -108,61 +112,59 @@
</div>
<div class="space-y-10">
- {#if transactions.length}
- {#each transactions as tx}
- <div class="grid grid-cols-3 border-b pb-5">
- <div class="whitespace-nowrap">
- <div class="mb-1 font-bold">
- {f(tx.amount * (tx.rate / sats), tx.currency)}
+ {#each $txns as tx}
+ <div class="grid grid-cols-3 border-b pb-5">
+ <div class="whitespace-nowrap">
+ <div class="mb-1 font-bold">
+ {f(tx.amount * (tx.rate / sats), tx.currency)}
- {#if tx.tip}
- <span class="text-sm">
- +{f(tx.tip * (tx.rate / sats), tx.currency)}
- </span>
- {/if}
- </div>
+ {#if tx.tip}
+ <span class="text-sm">
+ +{f(tx.tip * (tx.rate / sats), tx.currency)}
+ </span>
+ {/if}
+ </div>
- <span class="text-secondary"
- >{sat(tx.amount)}
+ <span class="text-secondary"
+ >{sat(tx.amount)}
- {#if tx.tip}
- <span class="text-sm">
- +{sat(tx.tip)}
- </span>
- {/if}
- </span>
- </div>
+ {#if tx.tip}
+ <span class="text-sm">
+ +{sat(tx.tip)}
+ </span>
+ {/if}
+ </span>
+ </div>
- <div class="flex">
- {#if tx.with}
- <a href={`/${tx.with.username}`} class="mx-auto">
- <div class="flex">
- <div class="my-auto">
- <Avatar user={tx.with} size={12} />
- </div>
- <div class="my-auto ml-1 text-secondary">{tx.with.username}</div>
+ <div class="flex">
+ {#if tx.with}
+ <a href={`/${tx.with.username}`} class="mx-auto">
+ <div class="flex">
+ <div class="my-auto">
+ <Avatar user={tx.with} size={12} />
</div>
- </a>
- {:else}
- <div class="mx-auto text-secondary">
- {tx.amount > 0 ? 'Received' : 'Sent'}
+ <div class="my-auto ml-1 text-secondary">{tx.with.username}</div>
</div>
- {/if}
- </div>
-
- <div class="text-secondary text-right">
- <div>
- {format(parseISO(tx.createdAt), 'h:mm aaa')}
- </div>
- <div>
- {format(parseISO(tx.createdAt), 'MMM d')}
+ </a>
+ {:else}
+ <div class="mx-auto text-secondary">
+ {tx.amount > 0 ? (tx.confirmed ? 'Received' : 'Pending') : 'Sent'}
</div>
+ {/if}
+ </div>
+
+ <div class="text-secondary text-right">
+ <div>
+ {format(parseISO(tx.createdAt), 'h:mm aaa')}
+ </div>
+ <div>
+ {format(parseISO(tx.createdAt), 'MMM d')}
</div>
</div>
- {/each}
+ </div>
{:else}
<p class="text-secondary text-lg text-center">{$t('user.transactions.empty')}</p>
- {/if}
+ {/each}
</div>
</div>
</div>